package Browser;

import java.util.LinkedList;

public class Browser {
	private LinkedList<String> forwardUrls;
	private LinkedList<String> backUrls;
	private String now=null;
	
	Browser(){
		forwardUrls=new LinkedList<>();
		backUrls=new LinkedList<>();
	}
	
	public String back() {
		if (forwardUrls.isEmpty()) {
			return null;
		}
		backUrls.push(now);
		now=forwardUrls.pop();
		return now;
	}
	
	public String forward() {	
		if (backUrls.isEmpty()) {
			return null;
		}

		return visit(backUrls.pop());
	}
	
	public String visit(String url) {
		if (now!=null) {
			forwardUrls.push(now);
		}
		return now=url;
	}

}
